package com.yanfan.ccapi.controller;

import com.yanfan.ccapi.service.ICcapiDeviceMappingService;
import com.yanfan.ccapicode.dao.entity.DeviceMappingDO;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 云云对接设备映射Controller
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@RestController
@RequestMapping("/ccapi/deviceMapping")
@Api(tags = "云云对接设备映射")
public class CcapiDeviceMappingController extends BaseController {
    @Autowired
    private ICcapiDeviceMappingService ccapiDeviceMappingService;

    /**
     * 查询云云对接设备映射列表
     */
//@PreAuthorize("@ss.hasPermi('ccapi:deviceMapping:list')")
    @GetMapping("/list")
    @ApiOperation("查询云云对接设备映射列表")
    public TableDataInfo list(DeviceMappingDO ccapiDeviceMapping) {
        startPage();
        List<DeviceMappingDO> list = ccapiDeviceMappingService.selectCcapiDeviceMappingList(ccapiDeviceMapping);
        return getDataTable(list);
    }

    /**
     * 导出云云对接设备映射列表
     */
    @ApiOperation("导出云云对接设备映射列表")
    //@PreAuthorize("@ss.hasPermi('ccapi:deviceMapping:export')")
    @Log(title = "云云对接设备映射", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceMappingDO ccapiDeviceMapping) {
        List<DeviceMappingDO> list = ccapiDeviceMappingService.selectCcapiDeviceMappingList(ccapiDeviceMapping);
        ExcelUtil<DeviceMappingDO> util = new ExcelUtil<DeviceMappingDO>(DeviceMappingDO.class);
        util.exportExcel(response, list, "云云对接设备映射数据");
    }

    /**
     * 获取云云对接设备映射详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:deviceMapping:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取云云对接设备映射详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ccapiDeviceMappingService.selectCcapiDeviceMappingById(id));
    }

    /**
     * 新增云云对接设备映射
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:deviceMapping:add')")
    @Log(title = "云云对接设备映射", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增云云对接设备映射")
    public AjaxResult add(@RequestBody DeviceMappingDO ccapiDeviceMapping) {
        return toAjax(ccapiDeviceMappingService.insertCcapiDeviceMapping(ccapiDeviceMapping));
    }

    /**
     * 修改云云对接设备映射
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:deviceMapping:edit')")
    @Log(title = "云云对接设备映射", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改云云对接设备映射")
    public AjaxResult edit(@RequestBody DeviceMappingDO ccapiDeviceMapping) {
        return toAjax(ccapiDeviceMappingService.updateCcapiDeviceMapping(ccapiDeviceMapping));
    }

    /**
     * 删除云云对接设备映射
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:deviceMapping:remove')")
    @Log(title = "云云对接设备映射", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除云云对接设备映射")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ccapiDeviceMappingService.deleteCcapiDeviceMappingByIds(ids));
    }
}
